package Day07.Demo03;

import java.util.Random;
import java.util.Scanner;

/**
 * @author 韩映晖
 * @version 1.0
 * @date 2022/2/4 19:47
 */
public class Demo04RandomGame {
    public static void main(String[] args) {
        Random r = new Random();
        int randomNum = r.nextInt(100)+1;
        Scanner in = new Scanner(System.in);

        while (true){
            System.out.println("随机数范围[1~100]，请输入您猜测的数字：");
            int guessNum = in.nextInt();

            if (guessNum>randomNum){
                System.out.println("您猜测的数字大了，请重新猜测！");
            }else if (guessNum<randomNum){
                System.out.println("您猜测的数字小了，请重新猜测！");
            }else {
                System.out.println("恭喜您，猜对了，真棒！");
                break;//游戏结束，不再查找
            }
        }
        System.out.println("游戏结束！！");
    }
}
